package com.itheima.config;


import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

//TODO:配置SqlSessionFactory和MapperScannerConfigurer
public class MybatisConfig {

    @Bean
    public SqlSessionFactoryBean getSqlSessionFactoryBean(DataSource ds){

        SqlSessionFactoryBean factoryBean=new SqlSessionFactoryBean();

        //设置pojo包扫描
        factoryBean.setTypeAliasesPackage("com.itheima.domain");

        //设置连接池
        factoryBean.setDataSource(ds);

        return factoryBean;
    }

    @Bean
    public MapperScannerConfigurer getMapperScannerConfigurer(){
        MapperScannerConfigurer mc=new MapperScannerConfigurer();

        //设置dao层的接口扫描
        mc.setBasePackage("com.itheima.mapper");

        return mc;
    }

}
